package Lee_code;

import com.sun.org.apache.bcel.internal.generic.NEW;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;

/**
 * @author blh
 * @date 2024年07月03日 10:34
 */
public class Lee_47_73 {
    HashSet<List<Integer>> res = new HashSet<>();
    int len;

    public List<List<Integer>> permuteUnique(int[] nums) {
        HashSet<Integer> seen = new HashSet<>();
        len = nums.length;
        fullArrange(new ArrayList<>(), seen, nums);

        return new ArrayList<>(res);
    }

    private void fullArrange(ArrayList<Integer> list, HashSet<Integer> seen, int[] nums) {
        if (list.size() == len) {
            res.add(new ArrayList<>(list));
            return;
        }
        for (int i = 0; i < len; i++) {
            if (seen.contains(i)){
                continue;
            }
            seen.add(i);
            list.add(nums[i]);
            fullArrange(list, seen, nums);
            seen.remove(i);
            list.remove(list.size()-1);
        }
    }
}
